if has("win32")
    let g:plug_file_path = "~/AppData/Local/nvim/plugged"
    let g:VIMPATH = "~/AppData/Local/nvim"
else
    let g:plug_file_path = "~/.config/nvim/plugged"
    let g:VIMPATH = "~/.config/nvim"
endif
let g:numberStatus = 0

if !has('nvim')
    for i in range(97,122)
        let c = nr2char(i)
        exec "set <A-".c.">=".c.""
    endfor
	nnoremap <Esc>q :q!<cr>
    exec "set <A-->=\e-"
    exec "set <A-->=\e="
    let &t_SI.="\e[5 q" "SI = INSERT mode
    let &t_SR.="\e[4 q" "SR = REPLACE mode
    let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE)
endif

command! -bar SplitRight :set splitright|:vsplit
command! EditMap SplitRight|exec 'e '.g:VIMPATH.'/map.vim'
command! EditPlug SplitRight|exec 'e '.g:VIMPATH.'/plug.vim'
command! EditInput SplitRight|exec 'e input.txt'
command! EditOutput SplitRight|exec 'e output.txt'
command! MyEsc :nohl|:set nocursorcolumn|exec 'source '.g:VIMPATH.'/numberOff.vim'|:let g:numberStatus=0

if g:KEYBORD_TYPE == "colemak"
    source ~/AppData/Local/nvim/colemak.vim
    " exec 'source '.g:VIMPATH.'/colemak.vim'
else
    source ~/AppData/Local/nvim/qwer.vim
    " exec 'source '.g:VIMPATH.'/qwer.vim'
endif

nnoremap <LEADER>rc :SplitRight<CR>:e $MYVIMRC<CR>
nnoremap <LEADER>mp :EditMap<CR>
nnoremap <LEADER>pl :EditPlug<CR>
nnoremap <LEADER>gi :BlamerToggle<CR>
nnoremap <nowait> <Esc> :MyEsc<CR>

nnoremap <leader>[[ :s/\[/\{/g<cr>:s/\]/\}/g<cr>
tnoremap <esc> <C-\><C-N>
noremap b B
noremap B b
noremap w W
noremap W w


" colemak
" noremap h i
" noremap H I
" noremap j e
" noremap J E
" noremap k n
" noremap K N
" noremap l u
" noremap L <C-r>
" noremap ge gj
" noremap gu gk
" noremap n h
" noremap N ^
" noremap I $
" noremap i l
" noremap e j
" nnoremap E 10j
" vnoremap E 3j
" noremap u k
" nnoremap U 10k
" vnoremap U 3k
" noremap <A-e> <nop>
" noremap <A-I> <C-w><Right>
" noremap <A-N> <C-w><Left>
" noremap <A-E> <C-w><Down>
" noremap <A-U> <C-w><Up>
" nnoremap <A-n> :-tabnext<CR>
" nnoremap <A-i> :+tabnext<CR>
" inoremap <A-i> <Right>
" inoremap <A-n> <Left>
" noremap <A-u> <nop>

noremap ]p p
noremap p ]p
map <silent> <leader>le gg/class<cr>V%y<c-o><c-o><c-o>:nohl<cr>
map <leader>dle gg/class<cr>V%<right>x:nohl<cr>
noremap <LEADER>ay ggyG
noremap <LEADER>ad ggdG
noremap <LEADER>ap ggVGP
noremap <LEADER>qn @n
noremap @ @n
noremap <LEADER>e :e!<CR>
noremap <A-f> /
noremap <LEADER><LEADER> zR<Esc>/>++><CR>:nohlsearch<CR>c4l
noremap <LEADER>pp zR<Esc>/>++><CR>:nohlsearch<CR>"84x<Left>p
noremap <LEADER>ll :set cursorcolumn<CR>
nnoremap - <C-o>
nnoremap = <C-i>
inoremap <A-o> <nop>
noremap s <nop>
" noremap <leader>si :set splitright<CR>:vsplit<CR>
" noremap <leader>sn :set nospr<CR>:vsplit<CR>
" noremap <leader>se :set splitbelow<CR>:split<CR>
" noremap <leader>su :set nosplitbelow<CR>:split<CR>
noremap <LEADER>ta :tabe<CR>
" noremap tt :NERDTreeToggle<CR>
noremap tt :FZF<CR>
" noremap ; :

" nmap <CR> <nop>
nnoremap <up> :res +5<CR>
nnoremap <down> :res -5<CR>
nnoremap <left> :vertical resize -5<CR>
nnoremap <right> :vertical resize +5<CR>
nnoremap <A-q> :q!<CR>
nnoremap <A-w> :w<CR>
nnoremap <A-r> :source $MYVIMRC<CR>:silent CocRestart<cr>
" nnoremap  <A-t> :CocCommand explorer<CR>
noremap <LEADER>ww :w !sudo tee %<CR>
nnoremap <LEADER>coc :set splitright<CR>:vsplit<CR>:CocConfig<CR>
noremap! <A-w> <Esc>:w<CR>
" noremap!   <Esc>
noremap <A-o> o<Esc>O
nnoremap > >>
nnoremap < <<
" nnoremap <LEADER>lg :call system('st -e sh -c lazygit')<cr>
nnoremap <LEADER>lg :call system('start cmd /c "lazygit"')<cr>
nnoremap <leader>in :EditInput<cr>
nnoremap <leader>ou :EditOutput<cr>
nnoremap <LEADER>ff :silent Vifm<CR>
nnoremap <LEADER>d <C-]>

" fold and unfold {{{
noremap <LEADER>oo za
noremap <LEADER>zf :call Fold()<CR>
function! Fold()
    if &filetype=='cpp'
        exec 'normal! zfa{'
    else
        exec 'normal! zfip'
    endif
endfunction
" }}}

" markdown shortcut key {{{
autocmd Filetype markdown inoremap <buffer> ;f <Esc>/<++><CR>:nohlsearch<CR>c4l
autocmd Filetype markdown nnoremap <buffer> ;f <Esc>/<++><CR>:nohlsearch<CR>c4l
autocmd Filetype markdown inoremap <buffer> ;s <Esc>/ <++><CR>:nohlsearch<CR>c5l
autocmd Filetype markdown inoremap <buffer> ;- ---<Enter><Enter>
autocmd Filetype markdown inoremap <buffer> ;b **** <++><Esc>F*hi
autocmd Filetype markdown inoremap <buffer> ;x ~~~~ <++><Esc>F~hi
autocmd Filetype markdown inoremap <buffer> ;x ** <++><Esc>F*i
autocmd Filetype markdown inoremap <buffer> ;q `` <++><Esc>F`i
autocmd Filetype markdown inoremap <buffer> ;c ```<Enter><++><Enter>```<Enter><Enter><++><Esc>4kA
autocmd Filetype markdown inoremap <buffer> ;g - [ ] <Enter><++><ESC>kA
autocmd Filetype markdown inoremap <buffer> ;u <u></u><++><Esc>F/hi
autocmd Filetype markdown inoremap <buffer> ;p ![](<++>) <Enter><++><Esc>kF[a
autocmd Filetype markdown inoremap <buffer> ;a [](<++>) <++><Esc>F[a
" []
autocmd Filetype markdown inoremap <buffer> ;1 #<Space><Enter><++><Esc>kA
autocmd Filetype markdown inoremap <buffer> ;2 ##<Space><Enter><++><Esc>kA
autocmd Filetype markdown inoremap <buffer> ;3 ###<Space><Enter><++><Esc>kA
autocmd Filetype markdown inoremap <buffer> ;4 ####<Space><Enter><++><Esc>kA
autocmd Filetype markdown inoremap <buffer> ;t <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR>
" }}}

inoremap ,fj >++>
" noremap! ,n \n
noremap!  <Esc>


" imap aa <c-r>=1+1<cr>
inoremap <A-h> <c-r>=Numbertoggle()<cr>
inoremap ` <c-r>=Numbertoggle()<cr>
function! Numbertoggle()
    if g:numberStatus == 0
        let g:numberStatus=1
        exec 'source '.g:VIMPATH.'/numberOn.vim'
    else
        let g:numberStatus=0
        exec 'source '.g:VIMPATH.'/numberOff.vim'
    endif
    return ""
endfunc

cnoremap  <C-c>


" no work
" noremap K N
